package file;

import java.io.File;
import java.util.Scanner;

public class FileDemo3 {
    public static void main(String[] args) {
        final var dir = getDir();
        System.out.println(dir);

    }
    public static File getDir() {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入文件夹路径：");
        while (true) {
            String path = sc.nextLine();
            File dir = new File(path);
            if (!dir.exists()) {
                System.out.println("文件夹路径不存在，请重新输入！");
            } else if (dir.isFile()) {
                System.out.println("输入的是文件路径，请重新输入文件夹路径:");
            } else {
                return dir.getAbsoluteFile();
            }
        }
    }

}
